package com.gregbugaj.reflector.test;

import static org.junit.Assert.*;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.gregbugaj.jsfconsole.util.ReflectUtil;
import com.gregbugaj.jsfconsole.util.reflection.BeanReflectionProvider;
import com.gregbugaj.jsfconsole.util.reflection.ReflectionProviderStrategy;
import com.gregbugaj.reflector.test.model.AddressWithPrivateFields;

/**
 * Test functionality of the {@link BeanReflectionProvider} class
 * @author devil
 *
 */
public class BeanReflectionProviderTester {
	
	private AddressWithPrivateFields obj;
	private ReflectionProviderStrategy reflectProvider;
	
	@Before
	public void setup(){
		reflectProvider = new BeanReflectionProvider();
		obj=new AddressWithPrivateFields();
		obj.setAddress("182 Str");
		obj.setStreet("Kilinskiego");
		obj.setHouse("10222");
	}
	
	@Test
	public void getPrivateProperties(){
		int expectedFieldCount=3;
		//Expecting 3 field because we should not have transient field
		//and there is a field without a getter 
		List<Field> fileds = reflectProvider.getAccesibleFields(obj);
		assertEquals(expectedFieldCount, fileds.size());
	}
	
	
	@Test
	public void fieldWithoutGetter(){
		//Expecting 2 field because we should not have transient field
		Field field = reflectProvider.getAccesibleField("secondaryAddress", obj);
		assertEquals(null, field);
	}
	
	
	@Test
	public void getMethdods(){
		int expectedMethodCount=4;
		List<Method> methods = reflectProvider.getMethods(obj.getClass());
		assertEquals(expectedMethodCount, methods.size());
	}
}






